const tools = {
	   /**
	     * @description 详细判断是否为手机号
	     * @param {String} str 要匹配的手机号
	     * @returns {Boolean} 返回 匹配结果
	     */
	    isPhone(str) {
	        let reg = /^(0|86|17951)?1[0-9]{10}$/;
	        if (reg.test(str)) {
	            return true;
	        } else {
	            return false;
	        }
	    },
		
	    isName(str) {
	        let reg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,5}$/;
	        if (reg.test(str)) {
	            return true;
	        } else {
	            return false;
	        }
	    },
		// 页面加载处理
		loadIng(msg){
			uni.showLoading({
				title:msg||'加载中....',
				mask:true
			})
			setTimeout(function(){
				uni.hideLoading();
			},1000)
		},
		showToast(msg){
			uni.showToast({
				title:msg,
				duration:2000,
				icon:'none'
			})
		},
		hideLoading(){
			uni.hideLoading();
		},
		formatDate(timestamp,day) {
			 var  date =  new  Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
			 let Y = date.getFullYear() +  '-' ;
			 let M = (date.getMonth()+1 < 10 ?  '0' +(date.getMonth()+1) : date.getMonth()+1) +  '-';
			 let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
			 let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
			 let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
			 let s = date.getSeconds()< 10 ?  '0' +date.getSeconds() : date.getSeconds();
			 let reluset=''
			 if(day){
				 reluset=Y+M+D
			 }else{
				 reluset=Y+M+D+h+m+s
			 }
			 return  reluset;
		},
		formatDay(timestamp){
			var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
			let Y = date.getFullYear() + '-';
			let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
			let D = date.getDate() < 10 ? '0' + date.getDate(): date.getDate();
			let reluset = ''
			reluset=Y+M+D
			return reluset;
		},
		fDate(date) {
					let timestamp = Date.parse(date)
					if(('' + timestamp).length <= 10) {
						timestamp = timestamp * 1000
					}
					
					var formats = {
						'year': '%n% 年前',
						'month': '%n% 月前',
						'day': '%n% 天前',
						'hour': '%n% 小时前',
						'minute': '%n% 分钟前',
						'second': '%n% 秒前',
					}
					var now = Date.now()
					var seconds = Math.floor((now - timestamp) / 1000)
					var minutes = Math.floor(seconds / 60)
					var hours = Math.floor(minutes / 60)
					var days = Math.floor(hours / 24)
					var months = Math.floor(days / 30)
					var years = Math.floor(months / 12)
					var diffType = ''
					var diffValue = 0
					if (years > 0) {
						diffType = 'year'
						diffValue = years
					} else {
						if (months > 0) {
							diffType = 'month'
							diffValue = months
						} else {
							if (days > 0) {
								diffType = 'day'
								diffValue = days
							} else {
								if (hours > 0) {
									diffType = 'hour'
									diffValue = hours
								} else {
									if (minutes > 0) {
										diffType = 'minute'
										diffValue = minutes
									} else {
										diffType = 'second'
										diffValue = seconds === 0 ? (seconds = 1) : seconds
									}
								}
							}
						}
					}
					return formats[diffType].replace('%n%', diffValue)
				},
}
export default tools;